﻿package 
{
    import FunctionBar.*;
    import com.assist.server.*;
    import com.haloer.net.*;
    import fl.transitions.*;
    import fl.transitions.easing.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;

    public class FunctionBar extends MovieClip
    {
        public var _Body:SimpleButton;
        public var _Achievement:SimpleButton;
        public var _Faction:SimpleButton;
        public var _Black:MovieClip;
        public var _PackMessage:MovieClip;
        public var _FriendMessage:MovieClip;
        public var _Upgrade:SimpleButton;
        public var _Experience:TextField;
        public var _ExpLeft:MovieClip;
        public var _ExperienceBtn:SimpleButton;
        public var _ExpMiddle:MovieClip;
        public var _Friend:SimpleButton;
        public var _Practice:SimpleButton;
        public var _Research:SimpleButton;
        public var _SealSoul:SimpleButton;
        public var _Deploy:SimpleButton;
        public var _ExpRight:MovieClip;
        public var _Pack:SimpleButton;
        public var _StudyStunt:SimpleButton;
        public var _Fate:SimpleButton;
        private var _toolbar:Toolbar;
        private var _positionList:Object;
        private var _btnShow:Array;
        private var _onEnd:Function;
        private var _mcTime:Timer;
        private var _btnAdd:Array;
        private var _btnShowArray:Array;
        private var _mcArray:Array;
        private var _tween1:Tween;
        private var _tween2:Tween;
        private var _timer:Timer;
        private var _strX:int;
        private var _strY:int;
        private var _functionBtn:SimpleButton;
        private var _tween3:Tween;
        private var _tween4:Tween;
        private var _light:MovieClip;
        private var _video:MovieClip;

        public function FunctionBar() : void
        {
            this._btnShow = [];
            this._onEnd = new Function();
            this._mcTime = new Timer(20);
            this._btnAdd = [];
            this._mcArray = [];
            this._timer = new Timer(10);
            addEventListener(Event.ADDED_TO_STAGE, this.addedToStage);
            this._mcTime.addEventListener(TimerEvent.TIMER, this.mcTimeHandler);
            return;
        }// end function

        public function set onEnd(param1:Function) : void
        {
            this._onEnd = param1;
            return;
        }// end function

        private function addedToStage(event:Event) : void
        {
            this._toolbar = parent as Toolbar;
            removeEventListener(Event.ADDED_TO_STAGE, this.addedToStage);
            this.removePackFull();
            return;
        }// end function

        public function getPointByType(param1:String) : Point
        {
            var _loc_4:Object = null;
            var _loc_2:* = this._btnShowArray.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_4 = this._btnShowArray[_loc_3];
                if (param1 == _loc_4.name)
                {
                    return localToGlobal(_loc_4.point);
                }
                _loc_3 = _loc_3 + 1;
            }
            return new Point(0, 0);
        }// end function

        public function show(param1:Array, param2:Array) : void
        {
            this._btnShow = param1;
            this._btnAdd = param2;
            this.renderLive();
            this.checkBtnCoordinates();
            return;
        }// end function

        private function renderLive() : void
        {
            if (this._positionList == null)
            {
                return;
            }
            var _loc_1:* = FunctionType.FullList;
            var _loc_2:* = _loc_1.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                this["_" + _loc_1[_loc_3]].x = this._positionList[(_loc_2 - 1) - _loc_3];
                this["_" + _loc_1[_loc_3]].visible = true;
                _loc_3 = _loc_3 + 1;
            }
            return;
        }// end function

        private function checkBtnCoordinates() : void
        {
            this._positionList = {};
            var _loc_1:* = FunctionType.FullList;
            var _loc_2:* = _loc_1.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                this._positionList[(_loc_2 - 1) - _loc_3] = this["_" + _loc_1[_loc_3]].x;
                this["_" + _loc_1[_loc_3]].visible = false;
                _loc_3 = _loc_3 + 1;
            }
            this._btnShowArray = [];
            var _loc_4:* = this._btnShow.length;
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4)
            {
                
                this.render(this._btnShow, _loc_4, _loc_5);
                this._btnShowArray[_loc_5].mc.x = this._btnShowArray[_loc_5].x;
                _loc_5 = _loc_5 + 1;
            }
            if (this._btnShow.length >= this._btnAdd.length)
            {
                this.blackLeng(false);
                return;
            }
            this.blackLeng(true);
            this.onAddMc();
            this.loadEffect();
            return;
        }// end function

        private function renderBtn() : void
        {
            var _loc_1:* = this._btnShow.length;
            this._btnShowArray = [];
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1)
            {
                
                this.render(this._btnShow, _loc_1, _loc_2);
                this._tween1 = new Tween(this._btnShowArray[_loc_2].mc, "x", Strong.easeIn, this._btnShowArray[_loc_2].x, this._strX, _loc_1 * 0.7, false);
                _loc_2 = _loc_2 + 1;
            }
            this._tween1.addEventListener(TweenEvent.MOTION_FINISH, this.onMc1Finish);
            return;
        }// end function

        private function renderMc2() : void
        {
            var _loc_1:* = this._btnAdd.length;
            this._btnShowArray = [];
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1)
            {
                
                this.render(this._btnAdd, _loc_1, _loc_2);
                this._tween2 = new Tween(this._btnShowArray[_loc_2].mc, "x", Back.easeOut, this._strX, this._positionList[(_loc_1 - 1) - _loc_2], _loc_1 * 2, false);
                _loc_2 = _loc_2 + 1;
            }
            this._tween2.addEventListener(TweenEvent.MOTION_FINISH, this.onMc2Finish);
            this._timer.addEventListener(TimerEvent.TIMER, this.onTimerEvent);
            this._timer.start();
            return;
        }// end function

        private function onTimerEvent(event:TimerEvent) : void
        {
            if (this._functionBtn.alpha < 1)
            {
                this._functionBtn.alpha = this._functionBtn.alpha + 0.01;
            }
            else
            {
                this._timer.stop();
                this._timer.removeEventListener(TimerEvent.TIMER, this.onTimerEvent);
            }
            return;
        }// end function

        private function onAddMc() : void
        {
            var _loc_1:* = this._btnShow.length;
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1)
            {
                
                if (this._btnShow[_loc_2] != this._btnAdd[_loc_2])
                {
                    this._strX = this._positionList[_loc_1 - _loc_2];
                    this._strY = this["_" + this._btnShow[_loc_2]].y;
                    this._functionBtn = this["_" + this._btnAdd[_loc_2]];
                    this._functionBtn.alpha = 0;
                    return;
                }
                _loc_2 = _loc_2 + 1;
            }
            this._strX = this._positionList[0];
            this._strY = this["_" + this._btnAdd[_loc_1]].y;
            this._functionBtn = this["_" + this._btnAdd[_loc_1]];
            this._functionBtn.alpha = 0;
            return;
        }// end function

        private function loadEffect() : void
        {
            var file:File;
            if (this._light)
            {
                this.playLight();
                return;
            }
            file = new File();
            file.onComplete = function () : void
            {
                _light = file.getClassObject("Light") as MovieClip;
                _light.gotoAndStop(1);
                _video = file.getClassObject("MyVideo") as MovieClip;
                _video.gotoAndStop(1);
                _video.blendMode = BlendMode.SCREEN;
                _video.mouseEnabled = false;
                _video.mouseChildren = false;
                playLight();
                return;
            }// end function
            ;
            file.load(this._toolbar.addonsUrl + "function_bar_effect.swf");
            return;
        }// end function

        private function playLight() : void
        {
            addChild(this._light);
            this._light.x = 0;
            this._light.y = -233;
            this._tween3 = new Tween(this._light, "x", Strong.easeIn, 0, this._strX, 20, false);
            this._tween4 = new Tween(this._light, "y", Strong.easeIn, -233, this._strY, 20, false);
            this._tween3.addEventListener(TweenEvent.MOTION_FINISH, this.onMc3Finsh);
            this._light.gotoAndPlay(2);
            return;
        }// end function

        private function playVideo() : void
        {
            addChild(this._video);
            this._video.x = this._strX;
            this._video.y = this._strY;
            this._video.addEventListener("finish", this.mcEnd);
            this._video.gotoAndPlay(2);
            return;
        }// end function

        private function onMc1Finish(event:TweenEvent) : void
        {
            this._tween1.removeEventListener(TweenEvent.MOTION_FINISH, this.onMc1Finish);
            this.renderMc2();
            return;
        }// end function

        private function onMc2Finish(event:TweenEvent) : void
        {
            this._tween2.removeEventListener(TweenEvent.MOTION_FINISH, this.onMc2Finish);
            this._onEnd();
            return;
        }// end function

        private function onMc3Finsh(event:TweenEvent) : void
        {
            this._tween3.removeEventListener(TweenEvent.MOTION_FINISH, this.onMc3Finsh);
            removeChild(this._light);
            this.playVideo();
            this.renderBtn();
            return;
        }// end function

        private function mcEnd(event:Event) : void
        {
            this._video.removeEventListener("finish", this.mcEnd);
            this.removeChild(this._video);
            return;
        }// end function

        private function render(param1:Array, param2:int, param3:int) : void
        {
            this["_" + param1[param3]].visible = true;
            var _loc_4:Object = {};
            _loc_4.mc = this["_" + param1[param3]];
            _loc_4.x = this._positionList[(param2 - 1) - param3];
            _loc_4.name = param1[param3];
            _loc_4.point = new Point(_loc_4.x, 47);
            this._btnShowArray[param3] = {};
            this._btnShowArray[param3] = _loc_4;
            return;
        }// end function

        private function mcTimeHandler(event:TimerEvent) : void
        {
            var _loc_2:* = this._btnAdd.length;
            var _loc_3:* = int(627 * (_loc_2 / 12));
            if (this._Black.width < _loc_3)
            {
                var _loc_4:* = this._Black;
                var _loc_5:* = this._Black.width + 1;
                _loc_4.width = _loc_5;
                this._Black._Head.x = -this._Black.width;
            }
            else
            {
                this._Black._Mid.width = _loc_3;
                this._Black._Head.x = -_loc_3;
                this._mcTime.stop();
            }
            return;
        }// end function

        private function blackLeng(param1:Boolean) : void
        {
            var _loc_2:* = this._btnAdd.length;
            var _loc_3:* = _loc_2 * 10;
            var _loc_4:* = int(627 * (_loc_2 / 12));
            this._Black._Mid.width = _loc_4;
            this._Black._Head.x = -_loc_4;
            return;
        }// end function

        public function addPackFull() : void
        {
            this.addChild(this._PackMessage);
            this._PackMessage.x = this._Pack.x - 10;
            return;
        }// end function

        public function removePackFull() : void
        {
            if (this._PackMessage.parent != null)
            {
                this._PackMessage.parent.removeChild(this._PackMessage);
            }
            return;
        }// end function

        public function updatePackMessageXY() : void
        {
            this._PackMessage.x = this._Pack.x - 10;
            return;
        }// end function

    }
}
